import pandas as pd
import os
# 读取指定列的数据
import requests
import pymysql

# 创建会话对象
session = requests.Session()
db = pymysql.connect(host='localhost', port=23306, user='root', password='Pr0dkcd_', db="kcdoc")
cursor = db.cursor()

def login():
    url = "http://127.0.0.1:22080/kcdoc/delegateLogin"
    payload = {'token': 'a9ddca2f934ba38007e7b9760a1e83b7'}
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    response = session.post(url, data=payload, headers=headers)
    data = response.text
    print(data)

def delete_user_image(userNo):
    delete = "DELETE FROM sys_att_t WHERE bus_type = 'esign' and bus_id = {}".format(userNo)
    cursor.execute(delete)
    db.commit()

def updateFile(filePath,user_no):
    url = "http://127.0.0.1:22080/kcdoc/uploadFile"
    payload = {'busType': 'esign','busId':user_no}
    files = {'file': open(filePath, 'rb')}
    response = session.post(url, data=payload, files=files)
    data = response.text
    print(user_no + "#######" + data)



def pullFile():
    # 指定目录路径
    directory = 'C:\\Users\\asus\\Desktop\\709\\name\\error'
    login()
    # 遍历目录中的文件
    for filename in os.listdir(directory):
        user_no =  filename.split('.')[0]
        if os.path.isfile(os.path.join(directory, filename)):
            # 读取文件
            with open(os.path.join(directory, filename), 'r') as file:
                if filename != '.DS_Store':
                    delete_user_image(user_no)
                    updateFile(directory + '\\' + filename,user_no)

if __name__ == '__main__':
     pullFile()


